import pika, sys
import time

credentials = pika.PlainCredentials("guest", "guest")
conn_params = pika.ConnectionParameters("localhost",credentials = credentials)
conn_broker = pika.BlockingConnection(conn_params)

channel = conn_broker.channel()
channel.exchange_declare(exchange="mandatory_exchange",
                         exchange_type="direct",
                         passive=False,
                         durable=True,
                         auto_delete=False)
channel.queue_declare(queue="mandatory_queue",durable=True)
channel.queue_bind(queue="mandatory_queue",
                   exchange="mandatory_exchange",
                   routing_key="hola")

#def callback(channel, method, header, body):
#    print "basic.return"
#channel.add_on_return_callback(callback)

channel.confirm_delivery()
result = channel.basic_publish(body="mandatory_message",
                         exchange="mandatory_exchange",
                         routing_key="hola",
                         mandatory=True)
print result

